package com.qcby.Controller;

import com.qcby.Entity.TrainOrder;
import com.qcby.Service.TrainNumService;
import com.qcby.query.TrainDetailQuery;
import com.qcby.query.TrainNumQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/TrainNum")
public class TrainNumController {


    @Autowired
    private TrainNumService trainNumService;

    @CrossOrigin
    @RequestMapping("/getTrainWithDetails")
    public List<TrainNumQuery> getTrainWithDetails(String time){
        return trainNumService.getTrainWithDetails(time);
    }

    @CrossOrigin
    @RequestMapping("/getTrainWithDetailsByTrainId")
    public TrainNumQuery getTrainWithDetailsByTrainId(Integer id){
        return trainNumService.getTrainWithDetailsByTrainId(id);
    }

    @CrossOrigin
    @PostMapping("/addTrainWithDetail")
    public void addTrainWithDetail(@RequestBody TrainNumQuery trainNumQuery){
        //System.out.println("被调用");
        //System.out.println(trainNumQuery.getName());
        //System.out.println(trainNumQuery.getTrainDetailQueries().size());
        trainNumService.addTrainWithDetail(trainNumQuery);
    }

    @CrossOrigin
    @DeleteMapping("/deleteTrainWithDetailById")
    public void deleteTrainWithDetailById(Integer id){
        //System.out.println(id);
        trainNumService.deleteTrainWithDetailById(id);
    }


    @CrossOrigin
    @GetMapping("/SearchTrainWithDetailsAndOrders")
    public List<TrainNumQuery> SearchTrainWithDetailsAndOrders(Integer fromStationId,Integer toStationId,String date){
        return trainNumService.SearchTrainWithDetailsAndOrders(fromStationId,toStationId,date);
    }

    @CrossOrigin
    @PostMapping("/buyTrainTicket")
    public TrainOrder buyTrainTicket(@RequestBody TrainOrder trainOrder){
        //System.out.println(trainOrder.toString());
        return trainNumService.buyTrainTicket(trainOrder);
    }

    @CrossOrigin
    @GetMapping("/SearchTrans")
    public List<List<TrainNumQuery>> SearchTransTrainWithDetails(Integer fromStationId,Integer toStationId,String date){
        return trainNumService.SearchTransTrainWithDetails(fromStationId,toStationId,date);
    }

    @CrossOrigin
    @PostMapping("/buyTransTicket")
    public List<TrainOrder> buyTransTrainTicket(@RequestBody List<TrainOrder> orderList){
        return trainNumService.buyTransTrainTicket(orderList);
    }
}
